In this step you will begin by creating a new project in Visual Studio 2010 and configuring the data source.
To configure the data source in Visual Studio 2010:
- Create a new WPF project in Microsoft Visual Studio 2010:
- Select File | New Project. The New Project dialog box opens.
- Expand the Visual C# node and select NET Framework 3.5. Note that you may have to expand the Other Languages node to find Visual C#.
- Choose WPF Application from the list of Templates in the right pane.
- Enter a name for your application in the Name field and click OK. A new project is created.
- From the Project menu, select Add Page. The Add New Item window appears. Visual C# will be selected under Categories, and Page (WPF) will be selected in the Templates pane.
- Leave Page1.xaml in the Name text box and click Add. The new Page1.xaml opens.
- If it is not already open, double-click Page1.xaml.cs under the Page1.xaml node in the Solution Explorer to open it.
- Add a reference to C1.WPF.Schedule:
- Select Project | Add Reference.
- Browse to find the location of the C1.WPF.dll and C1.WPF.Schedule assembly files. When Scheduler for Silverlight and WPF is installed, this file is installed to C:\Program Files\ComponentOne\WPF Edition\bin by default. Note that the location may be different if you performed a custom install.
- Add the following using statements to the Page1.xaml.cs page:
C# |
Copy Code
|
using C1.C1Schedule;
using MYProjectNAME.ScheduleDataSetTableAdapters;
|
Note that the using statement should contain the name of your project in order to work correctly. It will be used to set up the table adapter for your data set. The Imports statement should be used for Visual Basic projects.
- Add the data source you are binding to:
- Select Data | Add New Data Source. The Data Source Configuration Wizard appears.
- Select Database and click Next.
- Click the New Connection button and select Microsoft Access DataBase File from the Data Source group box and click Continue.
- Click Browse to browse to the Schedule.mdb database installed with Scheduler for Silverlight and WPF. This file was placed in the Common folder during installation.
- Click OK in the Add Connection dialog box and then click Next in the Data Source Configuration Wizard dialog box. If you are asked to copy the file to your project, you can click No. The connection is given a name.
- Click Next once you create the new connection.
- Click Next to save the connection string.
- Select the Tables node, leave ScheduleDataSet as the DataSet name, and click Finish.
- Add the following C# code to your Page1.xaml.cs Page1 class so it looks like the following. This code will use the data from the dataset to fill the schedule.
C# |
Copy Code
|
public partial class Page1 : System.Windows.Controls.Page
{
private ScheduleDataSet _schedulerDataSet = null;
public Page1()
{
InitializeComponent();
// Use the data set to fill in the data.
FillData(SchedulerDataSet);
}
public ScheduleDataSet SchedulerDataSet
{
get
{
if (_schedulerDataSet == null)
{
_schedulerDataSet = Resources["dataSet"] as ScheduleDataSet;
}
return _schedulerDataSet;
}
}
private void FillData(ScheduleDataSet ds)
{
if (ds == null)
return;
AppointmentsTableAdapter appAd = new AppointmentsTableAdapter();
appAd.Fill(ds.Appointments);
}
}
|
- Save and close the project.